package tr.edu.ozyegin.ccrg.raid.slave;

import java.io.IOException;
import java.net.UnknownHostException;

import tr.edu.ozyegin.ccrg.raid.config.ConfigManager;
import tr.edu.ozyegin.ccrg.raid.network.Client;
import tr.edu.ozyegin.ccrg.raid.network.ClientType;

public class Slave implements Runnable {
	protected Client client = null;
	protected ConfigManager conf = null;
	protected ClientType type = null;
	public Slave(String confFile){
		this.conf = ConfigManager.getInstance(confFile);
	}
	public Slave(){
		this.conf = ConfigManager.getInstance();
	}
	public void CreateConnection(String address, int port){
		this.client = new Client(address, port, this.type);
	}
	public void CreateConnection(){
		if(this.conf != null){
			int port = 0;
			try{
				port = Integer.parseInt(this.conf.searchByKey("raid.master.port").getValue());
			}
			catch(Exception e){
				System.out.println("The port number is not numeric...");
			}
			this.CreateConnection(this.conf.searchByKey("raid.master.address").getValue(), port);
		}
		else System.out.println("Please initialize the config manager...");
	}
	public void Connect() throws IOException, InterruptedException{
		if(this.client != null){
			this.client.Connect();
			this.doProtocol();
		}
		else System.out.println("Client is not created...");
	}
	protected void doProtocol() throws InterruptedException{
		
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		
	}
}
